package com.photoeditor.demo.ui.adapter.gallery;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.photoeditor.demo.app.XFragment;

import java.util.ArrayList;
import java.util.List;

public class GalleryFragmentPageAdapter extends FragmentPagerAdapter {

    private ArrayList<XFragment> mFragments;
    private List<String> mTitles;
    public XFragment currentFragment;

    public GalleryFragmentPageAdapter(FragmentManager fm, ArrayList<XFragment> data) {
        super(fm);
        mFragments = data;
    }

    @Override
    public Fragment getItem(int arg0) {
        if (mFragments != null) {
            return mFragments.get(arg0);
        }
        return null;
    }

    @Override
    public int getCount() {
        if (mFragments != null) {
            return mFragments.size();
        }
        return 0;
    }

    public void setData(ArrayList<XFragment> data) {
        mFragments = data;
    }

    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (mTitles != null) {
            return mTitles.get(position);
        }
        return super.getPageTitle(position);
    }

    public void setTitles(List<String> titles) {
        mTitles = titles;
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        currentFragment = (XFragment) object;
        super.setPrimaryItem(container, position, object);
    }
}
